/**
 * 
 */
package org.t2.backstage.module.gameserver.service;

import java.util.ArrayList;
import java.util.List;

import org.gaming.service.service.redis.OneToManyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.t2.backstage.module.gameserver.model.GameChannel;
import org.t2.backstage.module.gameserver.model.GameChannelServer;
import org.t2.backstage.module.gameserver.model.GameServer;

/**
 * @author YY
 *
 */
@Service
public class GameChannelService extends OneToManyService<GameChannel> {

	@Autowired
	private GameChannelServerService gameChannelServerService;
	@Autowired
	private GameServerService gameServerService;
	
	/**
	 * 获取渠道下的推荐服务器
	 * @param channelId
	 * @return
	 */
	public List<GameServer> getRecommendServersUnderChannel(long channelId) {
		List<GameChannelServer> relations = gameChannelServerService.getEntityList(channelId);
		List<GameServer> servers = new ArrayList<>();
		for(GameChannelServer relation : relations) {
			if(!relation.isRecommend()) {
				continue;
			}
			GameServer gameServer = gameServerService.getEntity(0L, relation.getServerUid());
			servers.add(gameServer);
		}
		return servers;
	}

	@Override
	protected String namespace() {
		return "system";
	}
}
